<template>
	<view class="mbti-login">
		<view class="mbti-login-content" :style="{'padding-top':contentTop+'rpx','background-image': `url(${bgUrl})`}">
			<view class="mbti-login-inner flex-column-start-center">
				<view class="login-top-info flex-row-between-center">
					<view class="login-info flex-row-start-center" @click="handleTest">
						<view class="login-avatar" style="margin-right: 28rpx;">
							<image class="cover-img" style="border-radius: 50%;" :src="avatarUrl" mode="aspectFill">
							</image>
						</view>
						<view class="login-tip">登录/注册</view>

					</view>
					<view class="right-control-icon flex-row-center-center">
						<image
							src="https://cdn.osisx.com/e416845113cdf0df55ad616de9bf72b2/image/33a0ab3240e444f182a3918d81d7ce4b.png"
							class="cover-img" mode="aspectFill"></image>
					</view>

				</view>
				<view class="login-center-info login-line-info-base">
					<view class="login-info-item" v-for="(item,index) in centerInfo" :key="index">
						<view class="info-item-content flex-row-between-center"
							@click="handleInfoItemClick(item,index)">
							<view class="info-item-inner flex-row-between-center">
								<view class="info-item-label flex-row-center-center">{{item.label}}</view>
								<view class="info-item-text flex-row-end-center" v-if="!item.value">{{item.tip}}</view>
								<view class="info-item-text info-item-text-value flex-row-end-center" v-else>
									{{item.value}}
								</view>
							</view>
							<view class="right-control-icon flex-row-center-center" style="margin-right: 4rpx;">
								<image
									src="https://cdn.osisx.com/e416845113cdf0df55ad616de9bf72b2/image/e9d6c0cf96c5447f968c5db37a1fb279.png"
									class="cover-img" mode="aspectFill"></image>
							</view>
						</view>

					</view>
				</view>
				<view class="login-bottom-info login-line-info-base">
					<view class="login-info-item flex-row-between-center" v-for="(item,index) in bottomInfo"
						:key="index">
						<view class="info-item-content flex-row-between-center">
							<view class="info-item-inner flex-row-between-center">
								<view class="info-item-label flex-row-center-center">{{item.label}}</view>
								<view class="info-item-text flex-row-end-center" v-if="!item.value">{{item.tip}}</view>
								<view class="info-item-text info-item-text-value flex-row-end-center" v-else>
									{{item.value}}
								</view>
							</view>
							<view class="right-control-icon flex-row-center-center" style="margin-right: 4rpx;">
								<image
									src="https://cdn.osisx.com/e416845113cdf0df55ad616de9bf72b2/image/e9d6c0cf96c5447f968c5db37a1fb279.png"
									class="cover-img" mode="aspectFill"></image>
							</view>
						</view>
					</view>

				</view>

			</view>
		</view>
		<mbtiPop ref="mbtiPop" @confirmValue="handleConfirmValue"></mbtiPop>
	</view>
</template>

<script>
	import mbtiPop from "@/components/m-mbti/mbti-pop.vue"
	export default {
		components: {
			mbtiPop
		},
		data() {
			return {
				screenWidth: 375,
				rpxMenuButtonHeight: 64,
				rpxMenuButtonTop: 100,
				contentTop: 300,
				bgUrl: "https://cdn.osisx.com/e416845113cdf0df55ad616de9bf72b2/image/d394a848c52a40a0b7fc9baf22ba6a01.png",
				avatarUrl: "https://cdn.osisx.com/e416845113cdf0df55ad616de9bf72b2/image/e3015edc8b2d425680c929fe5c4a59b3.png",
				centerInfo: [{
					label: "手机",
					tip: "关联你的手机",
					value: "19167041634"
				}, {
					label: "性别",
					tip: "选择你的性别",
					value: "男"
				}, {
					label: "生日",
					tip: "选择你的生日",
					value: ""
				}, ],

				bottomInfo: [{
						label: "关于Clackey",
						tip: "V1.1.02",
						value: ""
					},
					{
						label: "意见反馈",
						tip: "",
						value: ""
					},
				]

			}
		},
		created() {
			try {
				let screenWidth = uni.getStorageSync('screenWidth')
				if (screenWidth) {
					this.screenWidth = screenWidth
				} else {
					this.screenWidth = uni.getSystemInfoSync().screenWidth; // 当前设备屏幕宽度
					uni.setStorageSync("screenWidth", this.screenWidth)
				}
				let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
				let {
					top,
					height
				} = menuButtonInfo

				let rpxHeight = this.pxToRpx(height)
				let rpxTop = this.pxToRpx(top)
				this.rpxMenuButtonHeight = rpxHeight
				this.rpxMenuButtonTop = rpxTop

				this.contentTop = rpxTop + rpxHeight + 72

			} catch (error) {
				//TODO handle the exception
			}
		},
		methods: {
			handleTest() {
				// console.log("测试点击");
				// uni.showToast({
				// 	icon: "none",
				// 	title: "点中我"
				// })

			},
			handleInfoItemClick(item, index) {
				this.$refs.mbtiPop.open({
					data: [{
							label: "SSID",
							value: "",
							type: "label-in",
							valueType: "text",
							isRequire: true,
						},
						{
							label: "密码",
							value: "",
							type: "label-in",
							valueType: "password",
							isRequire: true,
						},
					],
					code: "center",
					title: `新的WIFI连接`
				})


			},
			handleConfirmValue(e) {
				// 弹修改成功？要不要做对比？
				// console.log("返回的是", e);
			},
			pxToRpx(px) {
				const designWidth = 750; // 设计稿宽度
				const rpx = (designWidth / this.screenWidth) * px; // 根据屏幕宽度计算 rpx
				return rpx;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.mbti-login {
		position: relative;
		width: 100vw;
		height: 100vh;
		background-color: #ededed;
		box-sizing: border-box;

		.mbti-login-content {
			width: 100%;
			height: 100%;
			background-repeat: no-repeat;
			background-size: cover;
			background-position: center center;

			.mbti-login-inner {
				width: 100%;
				padding: 0rpx 48rpx;

				.login-top-info {
					width: 100%;
					height: 104rpx;
					margin-bottom: 40rpx;
					padding-right: 32rpx;

					.login-info {
						flex: 1;
						height: 100%;

						.login-avatar {
							width: 104rpx;
							height: 104rpx;
							background-color: #fff;
							border-radius: 50%;
							// padding: 2rpx;
						}

						.login-tip {
							font-weight: 500;
							font-size: 40rpx;
							color: #979797;
							line-height: 56rpx;
							text-align: left;
						}
					}


				}

				.login-center-info {}

				.login-line-info-base {
					width: 100%;
					border-radius: 20rpx;
					background-color: #fff;
					margin-bottom: 40rpx;
				}

				.login-info-item {
					width: 100%;
					height: 116rpx;
					padding: 0rpx 28rpx;

					.info-item-content {
						position: relative;
						width: 100%;
						height: 100%;

						&::after {
							content: "";
							position: absolute;
							left: 0rpx;
							bottom: 0rpx;
							width: 100%;
							height: 0.5rpx;
							background-color: #ebebeb;
						}
					}

					.info-item-inner {
						flex: 1;
						height: 100%;
						margin-right: 28rpx;

						.info-item-label {
							height: 100%;
							font-weight: 300;
							font-size: 32rpx;
							color: #494949;
						}

						.info-item-text {
							flex: 1;
							height: 100%;
							font-weight: 400;
							font-size: 32rpx;
							color: #ebebeb;
							line-height: 40rpx;
						}

						.info-item-text-value {
							color: #494949;
						}
					}

					&:last-child {
						.info-item-content {
							&::after {
								display: none;
							}
						}
					}
				}
			}
		}
	}

	.right-control-icon {
		width: 12rpx;
		height: 20rpx;
	}
</style>